package com.quanyan.stadium.utils;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.quanyan.api.APIRequest;
import com.quanyan.common.utils.GsonUtils;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.orderpay.request.ReqOrderRefund;
import com.quanyan.stadium.constants.DatesportConstants;
import com.quanyan.stadium.constants.GameConstants;
import com.quanyan.stadium.entity.TbDatesportInfo;
import com.quanyan.stadium.entity.vo.MemberInfo;
import scala.Int;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Zheng.Ke
 * Date 2016/7/14.
 */
public final class DatesportHelper {
    private DatesportHelper () {

    }

    public static List<MemberInfo> getMemberListByMebersInfoStr(String membersInfo) {
        List<MemberInfo> memberInfoList = new ArrayList<>();
        if (StringUtil.isNotBlank(membersInfo)) {
            Gson gson = new GsonBuilder().create();
            Type type = new TypeToken<List<MemberInfo>>(){}.getType();
            memberInfoList = gson.fromJson(membersInfo, type);
        }
        return memberInfoList;
    }

    public static String getCreatorHeadUrlByMebersInfoStr(String membersInfo) {
        List<MemberInfo> memberInfoList = getMemberListByMebersInfoStr(membersInfo);
        if (memberInfoList.size() > 0) {
            return memberInfoList.get(0).getIcon();
        }
        return null;
    }

    public static String addMemberInfo(String originalMembersInfo, MemberInfo memberInfo) {
        List<MemberInfo> memberInfoList = getMemberListByMebersInfoStr(originalMembersInfo);
        if (memberInfo != null) {
            memberInfoList.add(memberInfo);
        }
        return GsonUtils.toJson(memberInfoList);
    }

    public static List<String> getTagListByTbDatesportInfo(TbDatesportInfo tbDatesportInfo) {
        List<String> tagList = new ArrayList<String>();
        if (tbDatesportInfo == null) {
            return tagList;
        }
        Byte sportType = tbDatesportInfo.getSportType();
        Integer playType = tbDatesportInfo.getPlayType();
        Byte playerTrait = tbDatesportInfo.getPlayerTrait();
        Byte playerLevel = tbDatesportInfo.getPlayerLevel();
        Byte costType = tbDatesportInfo.getCostType();
        Byte genderType = tbDatesportInfo.getGenderType();
        Byte timeFrame = tbDatesportInfo.getTimeFrame();
        Byte distanceRange = tbDatesportInfo.getDistanceRange();

        String tag = getSportType(sportType);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getPlayType(playType);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getPlayerTrait(playerTrait);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getPlayLevel(playerLevel);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getCostType(costType);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getGenderType(genderType);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getTimeFrame(timeFrame);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }
        tag = getDistanceRange(distanceRange);
        if (StringUtil.isNotBlank(tag)) {
            tagList.add(tag);
        }

        return  tagList;
    }

    private static String getPlayerTrait(Byte playerTrait) {
        String tag = null;
        if (playerTrait == null) {
            return tag;
        }
        switch (playerTrait) {
            case 1:
                tag = "运动达人";
                break;
            case 2:
                tag = "美女";
                break;
            case 3:
                tag = "帅哥";
                break;
            case 4:
                tag = "总裁俱乐部";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getDistanceRange(Byte distanceRange) {
        String tag = null;
        if (distanceRange == null) {
            return tag;
        }
        switch (distanceRange) {
            case 1:
                tag = "1km内";
                break;
            case 2:
                tag = "3km内";
                break;
            case 3:
                tag = "5km内";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getTimeFrame(Byte timeFrame) {
        String tag = null;
        if (timeFrame == null) {
            return tag;
        }
        switch (timeFrame) {
            case 1:
                tag = "今日";
                break;
            case 2:
                tag = "未来3天";
                break;
            case 3:
                tag = "未来7天";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getGenderType(Byte genderType) {
        String tag = null;
        if (genderType == null) {
            return tag;
        }
        switch (genderType) {
            case 0:
//                tag = "男女不限";
                break;
            case 1:
                tag = "限男";
                break;
            case 2:
                tag = "限女";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getCostType(Byte costType) {
        String tag = null;
        if (costType == null) {
            return tag;
        }
        switch (costType) {
            case 1:
                tag = "免费玩";
                break;
            case 2:
                tag = "论输赢";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getPlayLevel(Byte playerLevel) {
        String tag = null;
        if (playerLevel == null) {
            return tag;
        }
        switch (playerLevel) {
            case 1:
                tag = "纯属娱乐";
                break;
            case 2:
                tag = "专业水准";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getPlayType(Integer playType) {
        String tag = null;
        if (playType == null) {
            return tag;
        }
        switch (playType) {
            case 11:
                tag = "5人制";
                break;
            case 12:
                tag = "7人制";
                break;
            case 13:
                tag = "8人制";
                break;
            case 14:
                tag = "9人制";
                break;
            case 21:
                tag = "半场3v3";
                break;
            case 22:
                tag = "半场4v4";
                break;
            case 23:
                tag = "5v5全场";
                break;
            case 31:
                tag = "单打";
                break;
            case 32:
                tag = "双打";
                break;
            case 41:
                tag = "单打";
                break;
            case 42:
                tag = "双打";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }

    private static String getSportType(Byte sportType) {
        String tag = null;
        if (sportType == null) {
            return tag;
        }

        switch (Integer.valueOf(sportType)) {
            case GameConstants.CATEGORY_ID_FOOTBALL:
                tag = "足球";
                break;
            case GameConstants.CATEGORY_ID_BASKETBALL:
                tag = "篮球";
                break;
            case GameConstants.CATEGORY_ID_TENNIS:
                tag = "网球";
                break;
            case GameConstants.CATEGORY_ID_BADMINTON:
                tag = "羽毛球";
                break;
            case GameConstants.CATEGORY_ID_RUNNING:
                tag = "跑步";
                break;
            case GameConstants.CATEGORY_ID_RIDING:
                tag = "骑行";
                break;
            case GameConstants.CATEGORY_ID_GYM:
                tag = "户外";
                break;
            default:
                tag = null;
                break;
        }
        return tag;
    }
}
